FROM node:16-alpine as build-stage

# 设置工作目录
WORKDIR /app

# 复制前端项目文件
COPY package*.json ./
COPY . .

# 安装依赖并构建
RUN npm install && npm run build

# 生产阶段
FROM nginx:alpine

# 复制构建产物到Nginx目录
COPY --from=build-stage /app/dist /usr/share/nginx/html

# 复制自定义Nginx配置
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 暴露端口
EXPOSE 80

# 启动Nginx
CMD ["nginx", "-g", "daemon off;"]